package com.appwoo.txtws.service;

import android.app.Application;
import android.content.Context;
import com.appwoo.txtws.component.Logger;
import com.appwoo.txtws.thread.LocationTaskComplete;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;

public class WidgetLocation extends Application
{
  private String TAG = "location";
  private LocationTaskComplete complete;
  private int iRepeatTimes = 0;
  private MyBDLocationListenner mListenner = new MyBDLocationListenner();
  private LocationClient mLocationClient = null;
  private int myLocationTime = 600;
  private LocationClientOption option = null;

  public WidgetLocation(LocationTaskComplete paramLocationTaskComplete)
  {
    this.complete = paramLocationTaskComplete;
  }

  private void getLocationInfo()
  {
    switch (this.mLocationClient.requestLocation())
    {
    case 3:
    case 4:
    case 5:
    default:
      Logger.i(this.TAG, "requestLocation() : " + "其他原因\t");
      return;
    case 0:
      Logger.i(this.TAG, "requestLocation() : " + "正常。");
      return;
    case 1:
      Logger.i(this.TAG, "requestLocation() : " + "SDK还未启动。");
      return;
    case 2:
      Logger.i(this.TAG, "requestLocation() : " + "没有监听函数。 ");
      return;
    case 6:
    }
    Logger.i(this.TAG, "requestLocation() : " + "请求间隔过短。 ");
  }

  private void stopLocation()
  {
    try
    {
      if (this.mLocationClient != null)
        this.mLocationClient.stop();
      Logger.i(this.TAG, "关闭定位");
      return;
    }
    catch (Exception localException)
    {
      Logger.i(this.TAG, "关闭定位异常" + localException.toString());
    }
  }

  public void initLocation(Context paramContext)
  {
    try
    {
      if (this.mLocationClient == null)
      {
        this.mLocationClient = new LocationClient(paramContext);
        this.mLocationClient.registerLocationListener(this.mListenner);
        this.option = new LocationClientOption();
        this.option.setOpenGps(false);
        this.option.setCoorType("bd09ll");
        this.option.setPriority(2);
        this.option.setScanSpan(this.myLocationTime);
        this.mLocationClient.setLocOption(this.option);
      }
      return;
    }
    catch (Exception localException)
    {
      Logger.e(this.TAG, "打开定位异常" + localException.toString());
    }
  }

  public void startLocation()
  {
    try
    {
      if (this.mLocationClient != null)
      {
        if (this.mLocationClient.isStarted())
          break label34;
        this.mLocationClient.start();
      }
      while (true)
      {
        Logger.i(this.TAG, "开始定位");
        return;
        label34: getLocationInfo();
      }
    }
    catch (Exception localException)
    {
      Logger.i(this.TAG, "开始定位异常" + localException.toString());
    }
  }

  public class MyBDLocationListenner
    implements BDLocationListener
  {
    public MyBDLocationListenner()
    {
    }

    public void onReceiveLocation(BDLocation paramBDLocation)
    {
      if (paramBDLocation == null)
      {
        WidgetLocation localWidgetLocation2 = WidgetLocation.this;
        localWidgetLocation2.iRepeatTimes = (1 + localWidgetLocation2.iRepeatTimes);
        Logger.i(WidgetLocation.this.TAG, "location为空");
        if (WidgetLocation.this.iRepeatTimes <= 2)
          try
          {
            Thread.currentThread();
            Thread.sleep(5000L);
            WidgetLocation.this.startLocation();
            return;
          }
          catch (InterruptedException localInterruptedException2)
          {
            localInterruptedException2.printStackTrace();
            return;
          }
        WidgetLocation.this.stopLocation();
        WidgetLocation.this.iRepeatTimes = 0;
        return;
      }
      String str1 = paramBDLocation.getLongitude();
      String str2 = paramBDLocation.getAddrStr();
      if ((str1 != null) && (str2 != null))
      {
        String str3 = paramBDLocation.getCity();
        WidgetLocation.this.stopLocation();
        if (WidgetLocation.this.complete != null)
          WidgetLocation.this.complete.complete(str3);
        Logger.i(WidgetLocation.this.TAG, "定位关闭网络");
        return;
      }
      if ((WidgetLocation.this.iRepeatTimes == 2) && (WidgetLocation.this.complete != null))
        WidgetLocation.this.complete.complete(null);
      WidgetLocation localWidgetLocation1 = WidgetLocation.this;
      localWidgetLocation1.iRepeatTimes = (1 + localWidgetLocation1.iRepeatTimes);
      Logger.i(WidgetLocation.this.TAG, "location地址为空");
      if (WidgetLocation.this.iRepeatTimes <= 2)
        try
        {
          Thread.currentThread();
          Thread.sleep(5000L);
          WidgetLocation.this.startLocation();
          return;
        }
        catch (InterruptedException localInterruptedException1)
        {
          localInterruptedException1.printStackTrace();
          return;
        }
      WidgetLocation.this.stopLocation();
      WidgetLocation.this.iRepeatTimes = 0;
    }

    public void onReceivePoi(BDLocation paramBDLocation)
    {
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.service.WidgetLocation
 * JD-Core Version:    0.6.2
 */